/**
 * 
 */
package com.youyun56.gps.android;

import java.util.List;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.youyun56.gps.android.common.BaseActovity;
import com.youyun56.gps.android.dao.ImDao;
import com.youyun56.gps.android.pojo.Im;

public class ImsActivity extends BaseActovity {
    private final static String tag     = ImsActivity.class.getName();
    public static ImsHandler    handler;
    private ImItemAdapter       adapter = new ImItemAdapter(this);
    private View                emptyView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handler = new ImsHandler(this);
        Log.i(tag, "imactivity start");
        setContentView(R.layout.im);
        this.service = MainTabActivity.service;
        initImList();
    }
    
    private void initImList() {
        // TODO Auto-generated method stub
        ListView list = (ListView) findViewById(R.id.imList);
        emptyView = (LinearLayout) findViewById(R.id.emptyView);
        list.setAdapter(adapter);
        adapter.setListView(list);
        List<Im> ims = ImDao.getInstance().getAllIms();
        if (!ims.isEmpty()) {
            adapter.addAll(ims);
        } else {
            emptyView.setVisibility(View.VISIBLE);
        }
    }
    
    public ImItemAdapter getAdapter() {
        return adapter;
    }
    
    public View getEmptyView() {
        return emptyView;
    }
}
